package com.example.idachuappone.order.item;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.example.idachuappone.BaseActivity;
import com.example.idachuappone.R;
import com.example.idachuappone.order.adapter.ImageBucketAdapter;
import com.example.idachuappone.order.entity.ImageBucket;

public class AlbumListActivity extends BaseActivity implements OnItemClickListener, OnClickListener {
	private Button btn_back;
	private Button btn_index;
	List<ImageBucket> dataList;
	private ImageBucketAdapter imageBucketAdapter;
	private ListView listView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_album_list);
		initView();
		initData();
	}

	private void initData() {
		this.dataList = (List) getIntent().getSerializableExtra("listBuckets");
		initAdapter();
	}

	private void initView() {
		this.btn_back = (Button) findViewById(R.id.btn_back);
		this.btn_back.setOnClickListener(this);
		this.btn_index = (Button) findViewById(R.id.btn_index);
		this.btn_index.setOnClickListener(this);
		this.listView = (ListView) findViewById(R.id.listView1);
		this.listView.setOnItemClickListener(this);
		this.imageBucketAdapter = new ImageBucketAdapter(this);
		this.listView.setAdapter(this.imageBucketAdapter);
	}

	private void initAdapter() {
		this.imageBucketAdapter.setDataList(this.dataList);
		this.imageBucketAdapter.notifyDataSetChanged();
	}

	@Override
	public void onItemClick(AdapterView<?> adapterView, View arg1, int position, long arg3) {
		Intent data = new Intent();
		data.putExtra("index", position);
		setResult(-1, data);
		finish();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back /* 2131165198 */:
			setResult(0);
			finish();
		case R.id.btn_index /* 2131165213 */:
			setResult(0);
			finish();
		default:
		}
	}
}